<template>
  <el-form :model='form' label-width='120px'>
    <el-form-item label='Some thing：'>
      <el-input v-model='form.input' placeholder='Please write something...'></el-input>
    </el-form-item>
    <el-form-item label='Date time：'>
      <el-col :span='11'>
        <el-date-picker
          v-model='form.date'
          type='date'
          placeholder='Pick a date'
        ></el-date-picker>
      </el-col>
      <el-col :span='2' class="text-center">
        <span class="text-gray-500">-</span>
      </el-col>
      <el-col :span='11'>
        <el-time-picker
          v-model='form.time'
          placeholder='Pick a time'
        ></el-time-picker>
      </el-col>
    </el-form-item>
    <el-form-item>
      <el-button type='primary' @click="addTodo">
        ADD TODO
      </el-button>
    </el-form-item>
  </el-form>
</template>

<script setup>
  import { ref, reactive } from 'vue';
  import { useStore } from 'vuex';
  
  const store = useStore();

  let form = reactive({
    input: '',
    date: '',
    time: ''
  })

  const addTodo = () => {
    if (form.input !== '' && form.date !== '' && form.time !== '') {
      store.dispatch('addTodo', form)
      form.input = '';
      form.date = '';
      form.time = '';
    } else {
      alert('请先输入需要添加的Todo Item')
    }
    
  }

</script>

<style lang="scss">
  
</style>